import { createSlice } from '@reduxjs/toolkit'

const { name, reducer, actions } = createSlice({
  name: 'userRedux',
  initialState: {
    token: '',
  },
  reducers: {
    setToken(state, { payload }) {
      state.token = payload
      localStorage.setItem('token', payload)
    },
    removeToken(state) {
      state.token = ''
      localStorage.removeItem('token')
    },
  },
})

export default {
  name,
  reducer,
  actions: { ...actions }
}
